/**
 * Author : Fengyuan(Franklin) Zhang
 * Date : 2018/12/28
 * Description : MongoDB Connector
 */

var setting = require('../setting');
var mongoose = require('mongoose');
mongoose.Promise = require('bluebird');
var url = 'mongodb://' + setting.db.host + ':' + setting.db.port + '/' + setting.db.name;
mongoose.connect(url);

mongoose.connection.on('connected', function () {
    console.log('Mongoose connection open to ' + url);
});

mongoose.connection.on('error',function (err) {
    console.log('Mongoose connection error: ' + err);
});

mongoose.connection.on('disconnected', function () {
    console.log('Mongoose connection disconnected');
});

module.exports = mongoose;